package com.kingmed.kmss.admin.modules.sys.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kingmed.kmss.admin.modules.sys.model.SysOpenRelation;
import com.kingmed.kmss.admin.modules.sys.service.ISysOpenRelationService;
import com.kingmed.kmss.common.vo.CommonPage;
import com.kingmed.kmss.common.vo.CommonResponse;
import com.kingmed.kmss.common.vo.CommonResponseHelper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 对外授权接口关系
 * 
 * @author Sys
 * @date 2022-12-16
 */
@RestController
@RequestMapping("/sys/open/relation")
@Api(tags = "sys对外授权接口关系")
public class SysOpenRelationController
{
    @Autowired
    private ISysOpenRelationService sysOpenRelationService;

    /**
     * 查询对外授权接口关系列表
     */
    @ApiOperation("查询对外授权接口关系列表")
    @GetMapping("/list")
    public CommonResponse<CommonPage<SysOpenRelation>> list(SysOpenRelation SysOpenRelation,
                                                            @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                                            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum)
    {
        Page<SysOpenRelation> list = sysOpenRelationService.list(SysOpenRelation, pageNum, pageSize);
        return CommonResponseHelper.success(CommonPage.restPage((list)));
    }


    /**
     * 获取对外授权接口关系详细信息
     */
    @ApiOperation("获取对外授权接口关系详细信息")
    @GetMapping(value = "/{id}")
    public CommonResponse<SysOpenRelation> getInfo(@PathVariable("id") String id)
    {
        return CommonResponseHelper.success(sysOpenRelationService.selectSysOpenRelationById(id));
    }

    /**
     * 新增对外授权接口关系
     */
    @ApiOperation("新增对外授权接口关系")
    @PostMapping("/add")
    public CommonResponse<Boolean> add(@RequestBody SysOpenRelation SysOpenRelation)
    {
        return CommonResponseHelper.success(sysOpenRelationService.insertSysOpenRelation(SysOpenRelation));
    }

    /**
     * 批量新增对外授权接口关系
     */
    @ApiOperation("批量新增对外授权接口关系")
    @PostMapping("/batchAdd")
    public CommonResponse<Boolean> batchAdd(@RequestBody List<SysOpenRelation> SysOpenRelationList)
    {
        return CommonResponseHelper.success(sysOpenRelationService.saveBatchByList(SysOpenRelationList));
    }

    /**
     * 修改对外授权接口关系
     */
    @ApiOperation("修改对外授权接口关系")
    @PutMapping("/edit")
    public CommonResponse<Boolean> edit(@RequestBody SysOpenRelation SysOpenRelation)
    {
        return CommonResponseHelper.success(sysOpenRelationService.updateSysOpenRelation(SysOpenRelation));
    }

    /**
     * 删除对外授权接口关系
     */
    @ApiOperation("删除对外授权接口关系")
	@DeleteMapping("/remove/{ids}")
    public CommonResponse<Boolean> remove(@PathVariable String[] ids)
    {
        return CommonResponseHelper.success(sysOpenRelationService.deleteSysOpenRelationByIds(ids));
    }

    /**
     * 加载对外接口redis缓存
     */
    @ApiOperation("加载对外接口redis缓存")
    @PostMapping("/loadingCache")
    public void loadingCache()
    {
        sysOpenRelationService.loadingCache();
    }
}
